package org.gitman.agentplatform.ui.summary;

import java.util.LinkedList;

import javax.swing.table.AbstractTableModel;

import org.gitman.agentplatform.core.SimulationStatistic;

public class MultirunSummaryTabelModel extends AbstractTableModel{
	private LinkedList<SimulationStatistic> statistics;
	private static String [] columns = {
		"Nr", 
		"Rating", 
		"state", 
		"Observablity", 
		"Predictability",
		"Relieability",
		"Iterations",
		"Time"
	};
	private static int [] widths = {
		30,
		90,
		60,
		90,
		90,
		90,
		90,
		90
	};
	
	public MultirunSummaryTabelModel(LinkedList<SimulationStatistic> statistics) {
		this.statistics = statistics;
	}	
	
	@Override
	public int getRowCount() {
		return statistics.size();
	}

	@Override
	public int getColumnCount() {
		return columns.length;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		SimulationStatistic statistic = statistics.get(rowIndex);
		switch (columnIndex) {
		case 0:
			return (rowIndex+1)+"";
		case 1:
			return round(statistic.rating, 3);
		case 2:
			return statistic.state;
		case 3:
			return notNull(statistic.observ);
		case 4:
			return notNull(statistic.predict);
		case 5: 
			return statistic.relie == null ? notNull(statistic.relie) : round(statistic.relie, 5);
		case 6: 
			return statistic.iterations;
		case 7:
			return round(statistic.time, 3);

		default:
			return "###";
		}
		
	}
	
	@Override
	public String getColumnName(int column) {
		return columns[column];
	}

	public int[] getWidths() {
		return widths;
	}
	
	private double round(double val, int pos){
		double shift = 1.0;
		for(int i=0;i<pos;i++){
			shift *= 10.0;
		}
		val *= shift;
		return Math.round(val)/shift;		
	}
	
	private String notNull(Object o){
		if(o == null){
			return "-";
		}else{
			return o.toString();
		}
	}

}
